package javamusic.Servlet.Sala;

import java.io.IOException;
import java.util.Collection;

import javamusic.excepcion.DAOExcepcion;
import javamusic.modelo.Sala;
import javamusic.negocio.GestionSala;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import junit.framework.Assert;

/**
 * Servlet implementation class ServletSalaBuscar
 */
@WebServlet("/ServletSalaBuscar")
public class ServletSalaBuscar extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public ServletSalaBuscar() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String nombre = request.getParameter("nombre");
		GestionSala negocio = new GestionSala();
try{
	Collection<Sala> salas = negocio.buscarPorNombre(nombre);
	for (Sala sala : salas) {
		sala.getIdsala();
		sala.getNombre();
		sala.getCapacidad();
		sala.getDescripcion();
		sala.getElog();
		
		sala.getLocal();
					
	}
	RequestDispatcher rd = request.getRequestDispatcher("/FormSalaBuscar.jsp");
	request.setAttribute("SALAS_REGISTRADAS", salas);
	rd.forward(request, response);
} catch (DAOExcepcion e){
	Assert.fail("Fallo la Insercion:" + e.getMessage());
}
	}

	
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String nombre = request.getParameter("nombre");
				GestionSala negocio = new GestionSala();
		try{
			Collection<Sala> salas = negocio.buscarPorNombre(nombre);
			for (Sala sala : salas) {
				sala.getIdsala();
				sala.getNombre();
				sala.getCapacidad();
			sala.getDescripcion();
				sala.getElog();
				
				sala.getLocal();
							
			}
			RequestDispatcher rd = request.getRequestDispatcher("/FormSalaBuscar.jsp");
			request.setAttribute("SALAS_REGISTRADAS", salas);
			rd.forward(request, response);
		} catch (DAOExcepcion e){
			Assert.fail("Fallo la Insercion:" + e.getMessage());
		}
		
		
	}

}
